package com.lldpet.spring.cloud.demo.stream.demo.service.impl;

import com.lldpet.spring.cloud.demo.stream.demo.channel.BpsSource;
import com.lldpet.spring.cloud.demo.stream.demo.service.MessageProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

/**
 * @desc：BpsMessageProviderImpl 自定义通道消息发送
 * @author: guanliang.xue
 * @date: 2021/5/12 09:13
 * @version:
 * @since:
 */
@EnableBinding(BpsSource.class)
public class BpsMessageProviderImpl implements MessageProvider {

    private static final Logger logger = LoggerFactory.getLogger(BpsMessageProviderImpl.class);

    @Resource
    private BpsSource bpsSource;

    @Override
    public String send() {
        String msg = "自动消息通道 bpsSource 发送消息";
        boolean sendStatus = bpsSource.output().send(MessageBuilder.withPayload(msg).build());
        logger.info("发送数据: {}, 发送状态 sendStatus: {}",msg, sendStatus);
        return msg;
    }
}
